package site.wanjiahao.utils;

import site.wanjiahao.constant.FileConstant;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;

public class FileUtils {


    public static void download(String filePath, HttpServletResponse response) throws IOException {
        BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(filePath));
        ServletOutputStream outputStream = response.getOutputStream();
        byte[] bytes = new byte[FileConstant.TEMP_CACHE_SIZE];
        int len;
        while ((len = inputStream.read(bytes)) != -1) {
            outputStream.write(bytes, 0, len);
            outputStream.flush();
        }
        inputStream.close();
    }

}
